<?php
/**
 * Description:
 * Author: hezhizheng
 * Date: 2018/6/19
 * Time: 16:12
 * Created by Created by Panxsoft.
 */

namespace App\Services\Utils;

class RequestParam
{
    /**
     * 格式化不是必须的请求参数
     *
     * @param array $keys 需要的参数 key 名列表
     * @param array $merge_params 需要合并的参数
     *
     * @return array
     */
    public static function normalize(array $keys, array $merge_params = []): array
    {
        $data = [];
        $request = request();

        foreach ($keys as $param) {
            if ($request->has($param)) {
                $data[$param] = $request->{$param};
            }
        }

        return array_merge($data, $merge_params);
    }
}